<template>
	<view class='live_box'>
		<view style="color: #fff;padding: 30upx;padding-top: 50upx;display: flex;">
			<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
				<text :class="isshow ==1?'ggw':'gg'" @click="gets">我看过的</text>
				<text class="heng" v-show="isshow ==1"></text>
			</view>
			<view style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
				<text :class="isshow ==2?'ggw':'gg'" style="margin-left: 50upx;" @click="getd">看过我的</text>
				<text class="heng" v-show="isshow ==2" style="margin-left: 50upx;"></text>
			</view>
		</view>
		<scroll-view scroll-y="true" style="width: 100%;height: 1300upx;" v-if="isShow">

			<view v-if="isShow" class="live_list">
				<view class="live_item" v-for="(item,index) in shulist" :key='index' @click="navShop(index,item.id)">
					<view class="left">
						<avatar :img='item.headimgurl' :size="44"></avatar>
						<view class="vertical">
							<view class="name">{{item.user_name}}</view>
							<view class="is_status" style="color: #666666;">{{item.addtime}}</view>
						</view>
					</view>
					<view>{{item.is_follow}}</view>
					<!-- <view v-if='isshow ==2' class="no_follow" @click="navShop(index,item.id)">查看</view> -->
				</view>
				<view class="live_num_box" v-if="isshow ==1">
					我最近看过{{shunum}}人
				</view>
				<view class="live_num_box" v-if="isshow ==2">
					最近{{shunum}}人看过我
				</view>
			</view>
			<view class="none_box" v-else>
				暂时还没有关注喔!
			</view>
		</scroll-view>


	</view>
</template>
<script>
	import avatar from '../../components/avatar.vue'
	export default {
		name: 'homeSon',
		data() {
			return {
				list: [],
				clickLoading: false,
				countNum: 0,
				isShow: true,
				isshow:1,
				typeNum:1,
				shulist:[],
				shunum:'',
				page:1
			}
		},
		components: {
			avatar
		},

		onShow() {
			this.userInfo = this.$store.getters.getuserInfo
			// this.initData()
			console.log("有没有用户信息",this.userInfo)
			try {
				const value = uni.getStorageSync('userInfo');
				if (value) {
			
					this.userInfo = JSON.parse(value)
					console.log(this.userInfo,"视频信息")
					if(this.userInfo.status==400){
						uni.navigateTo({
							url:'/pagesB/login/login'
						})
					}
				}else{
					uni.navigateTo({
						url:'/pagesB/login/login'
					})
				}
			} catch (e) {
				// error
			}
			this.$http.getliulan({type: this.isshow,page:this.page}).then(res => {
				console.log("获取浏览",res)
				this.shulist = res.data.list
				this.shunum = res.data.num
			})
		},
		onLoad() {
			
			this.$http.getliulan({type: this.isshow,page:this.page}).then(res => {
				console.log("获取浏览",res)
				this.shulist = res.data.list
				this.shunum = res.data.num
			})
		},
		methods: {
			gets(){
				this.isshow = 1
				this.$http.getliulan({type: this.isshow,page:this.page}).then(res => {
					console.log("我看看奥",res)
					this.shulist = res.data.list
					this.shunum = res.data.num
				})
			},
			getd(){
				this.isshow = 2
				this.$http.getliulan({type: this.isshow,page:this.page}).then(res => {
					console.log("我看看奥",res)
					this.shulist = res.data.list
					this.shunum = res.data.num
				})
			},
			navShop(index,id) {
				if(this.shulist[index].shop_id==0){
					// alert(1)
					// uni.switchTab({
					// 	url:`/pages/tabBar/mydetail?userId=${id}`
					// })
					
					uni.navigateTo({
						url:`/pages/tabBar/uerinfo?userId=${id}`
					}) 
				}else{
					var name = "足迹"
					// alert(2)
					uni.navigateTo({
						url:`/pagesC/home/personage/personage?userId=${this.shulist[index].shop_id}&circle_id=0&typename=${name}`
					})
				}
				
			},
			initData() {
				this.$http.shopfollowlist({}).then(res => {
					console.log(res)
					if (res.status == 200) {
						this.list = res.data.shop.map(item => {
							item.is_follow = 1
							return item
						})
						if (this.list.length == 0) {
							this.isShow = false
						} else {
							this.isShow = true
						}
						this.countNum = res.data.count || 0
					} else {
						
						uni.showToast({
							title: res.mess,
							icon: 'none'
						})
						setTimeout(()=>{
							uni.redirectTo({
								url:'/pagesB/login/login'
							})
						},1500)
						this.isShow = false
					}
				}).catch(res => {
					this.isShow = false
				})
			},
			addfollow(index) {
				if (this.clickLoading) {
					uni.showToast({
						title: "点击过于频繁 ~",
						icon: "none",
						duration: 1000
					})
					return
				}
				if (this.userInfo === null || this.userInfo === undefined || this.userInfo === '') {
					uni.showToast({
						title: "登录后才可以关注 \r\n ∠( ᐛ 」∠)＿",
						icon: "none",
						duration: 2000
					})
					return
				}
				this.clickLoading = true
				let shop_id = this.list[index].shop_id
				this.$http.addfollow({
					shop_id
				}).then(res => {
					console.log(res)
					if (res.status == 200) {
						this.list[index].is_follow = 1
					}
					this.clickLoading = false
				}).catch(err => {
					this.clickLoading = false
				})
			},
			reduceFollow(index) {
				if (this.clickLoading) {
					uni.showToast({
						title: "点击过于频繁 ~",
						icon: "none",
						duration: 1000
					})
					return
				}
				if (this.userInfo === null || this.userInfo === undefined || this.userInfo === '') {
					uni.showToast({
						title: "登录后才可以关注 \r\n ∠( ᐛ 」∠)＿",
						icon: "none",
						duration: 2000
					})
					return
				}
				this.clickLoading = true
				let shop_id = this.list[index].shop_id
				this.$http.cancelfollow({
					shop_id
				}).then(res => {
					console.log(res)
					if (res.status == 200) {
						console.log('取消', this)
						this.list[index].is_follow = 0
						console.log(this.list)
					}
					this.clickLoading = false
				}).catch(err => {
					this.clickLoading = false
				})
			},

		}
	}
</script>
<style lang="less">
	.heng{
		width: 50upx;
		height: 8upx;
		background: #FF3D3D;
		border-radius: 3upx;
		display: inline-block;
	}
	.gg {
		font-size: 32upx;
		color: #FFFFFF;
	}

	.ggw {
		font-size: 32upx;
		color: #FF3D3D;
		font-weight: bold;
		// border-bottom: 4upx solid #FF3D3D;
		display: flex;
		flex-direction: column;
	}

	.live_box {
		background-color: #0F111D;
		// padding-top: 80rpx;
		// margin-top: 70upx;
		height: 100vh;

		.live_list {
			height: calc(100vh - 400rpx);
		}

		.none_box {
			width: 100vw;
			height: 30vh;
			line-height: 30vh;
			text-align: center;
			color: #fff;
			font-size: 40rpx;
		}

		.live_item {
			width: 94vw;
			margin: 30rpx 3vw;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.left {
				display: flex;
				align-items: center;
			}

			.vertical {
				display: flex;
				flex-direction: column;
				height: 88rpx;
				justify-content: space-around;
				margin-left: 15rpx;

				.name {
					font-size: 30rpx;
					color: #ffffff;
				}

				.is_status {
					font-size: 24rpx;
					color: #ffffff;
				}
			}

			.follow {
				width: 120rpx;
				height: 60rpx;
				background-color: #3a3a44;
				border-radius: 5rpx;
				line-height: 60rpx;
				font-size: 30rpx;
				color: #ffffff;
				text-align: center;
			}

			.no_follow {
				width: 120rpx;
				height: 60rpx;
				background-color: #ff3d3d;
				border-radius: 5rpx;
				line-height: 60rpx;
				font-size: 30rpx;
				color: #ffffff;
				text-align: center;
			}

		}

		.live_num_box {
			position: relative;
			width: 94vw;
			left: 3vw;
			bottom: -20rpx;
			height: 150rpx;
			line-height: 150rpx;
			// background: red;
			color: #999999;
			z-index: 99;
			text-align: center;
			border-top: 1px solid #333;
		}
	}
</style>
